package tcp1;
/*
 * 客户端
 */
import java.io.*;
import java.net.*;

public class Socket1  {
		 public static void main(String[] args) throws IOException{
			 //创建Socket套接字对象,用于与服务器获得连接
			Socket socket=new Socket("10.20.1.75",12654);
			System.out.println("客户端"+socket.getInetAddress().getHostAddress()+
					"的套接字对象socket创建成功");
			//创建输入流读取标准输入流的字符
			BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
			//socket对象获取字节输出流通过转换流转换成字符输出流
			BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(
					socket.getOutputStream()));
			//socket对象获取字节输入流并通过转换流转转成字符输入流
			BufferedReader reader2=new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
			while(true) {
				String data=reader.readLine();//获取键盘输入的字符串
					//换行writer.newLine();
					writer.write(data);//将数据写入输出流
					writer.newLine();//在文本行末尾加上一个换行符,程序默认换行符为终止写入的命令
					writer.flush();//刷新流
				
					if(data.equals("over")) {//如果标准输入流输入指定字符传则关闭写入操作
						System.out.println("结束程序");
						break;
					}
					System.out.println(reader2.readLine());
				}
			reader.close();
			reader2.close();
			writer.close();
			socket.close();
			}
			
		}
		

